<?php
$server =new \Swoole\WebSocket\Server("0.0.0.0", 9999);
$server->on('open', function (\Swoole\WebSocket\Server $server, $request) {
    echo "connection open: {$request->fd}\n";
});
$server->on('message', function (\Swoole\WebSocket\Server $server, $frame) {
    echo "receive from {$frame->fd}:{$frame->data}\n";
    foreach ($server->connections as $fd) {
        if($fd == $frame->fd) {
            continue;
        }
        if($server->isEstablished($fd)) {
            echo "send :{$frame->data}\n";
            $server->push($fd, $frame->data);
        }
    }
});
$server->on('close', function (\Swoole\WebSocket\Server $server, $fd) {
    echo "connection close: {$fd}\n";
});
$server->start();